DAY42:Consecutive strings


Posted by birdbirdmurmur on 2023-08-24

題目連結

https://www.codewars.com/kata/56a5d994ac971f1ac500003e

解法

function longestConsec(strarr, k) {
    if (k <= 0 || strarr.length === 0) {
        return '';
    }

    let long = ''
    for (let i = 0; i < strarr.length - k + 1; i++) {
        const currString = strarr.slice(i, i + k).join('')
        if (currString.length > long.length) {
            long = currString
        }
    }
    return long
}

筆記


#javascript #Codewars







Related Posts

Remove Duplicates from an Array (ES6)

Remove Duplicates from an Array (ES6)

01. Install Python, Flask and virtual environment

01. Install Python, Flask and virtual environment

Unveiling the Mystery: Understanding the Black Dot on Your Tooth

Unveiling the Mystery: Understanding the Black Dot on Your Tooth


Comments